home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / Solaris_2 / newwais.pl < prev    next >
Perl Script  |  1995-08-22  |  4KB  |  148 lines

  1. #!/net/pinatubo/opt/PUBperl5/bin/perl5
  2. #
  3. # newwais.pl -- WAIS search interface
  4. #
  5. # from wais.pl
  6. #
  7. # Tony Sanders <sanders@bsdi.com>, Nov 1993
  8. #
  9. # Example configuration (in local.conf):
  10. #     map topdir wais.pl &do_wais($top, $path, $query, "database", "title")
  11. #
  12. # this script uses a sneaky feature of Mosaic that interpretes a 
  13. # single text input form with the name 'isindex' (case sensitive) to
  14. # the same as a <ISINDEX>.  On non-mosaic clients, you wind up with an
  15. # additional query
  16. #
  17. # Note that I know even less about perl than the other two people
  18. # who hacked this, so feel free to send hate mail to pjh@netcom.com
  19. # if I did something really bad (or if there is a better way of
  20. # grabbing the filename off the end of a path.
  21. #
  22.  
  23. #require 'ctime.pl';
  24.  
  25. $waisq = "/opt/db/waisq";
  26. $waisd = "/opt/db/wais";
  27.  
  28.  
  29. $src = "catalyst_catalog";
  30. $title = "Example Data";
  31. #
  32. # file type map based on file extension, since all file types
  33. # come back type URL
  34. #
  35.  
  36. %filetype = (
  37. 'html', 'HTML File',
  38. );
  39.  
  40. #
  41. # code
  42.  
  43. sub send_index {
  44.     print "Content-type: text/html\n\n";
  45.     
  46.     print "<HEAD>\n<TITLE>Index of ", $title, "</TITLE>\n</HEAD>\n";
  47.     print "<BODY>\n<H1>", $title, "</H1>\n";
  48.  
  49.     print "This is an index of the information on this server. Please\n";
  50.     print "type a query in the search dialog.\n<P>";
  51.     print "You may use compound searches, such as: <CODE>environment AND cgi</CODE>\n";
  52.     print "<ISINDEX>";
  53. }
  54.  
  55. sub do_wais {
  56. #    local($top, $path, $query, $src, $title) = @_;
  57.  
  58. # strip the escape off of *'s
  59.     for (@ARGV){s/\\//g};
  60.  
  61.     do { &'send_index; return; } unless defined @ARGV;
  62.     local(@query) = @ARGV;
  63.     local($pquery) = join(" ", @query);
  64.  
  65. #
  66. # grab a wais source if there is one
  67. #
  68.  
  69.     local($test) = $ENV{'PATH_INFO'};
  70.     if ($test)
  71.     {
  72.     $test =~ s/\///;
  73.         $src = "catalyst_catalog";
  74.         $title = $test;
  75.     }
  76.  
  77.     close STDERR;
  78.     open(STDERR, ">/dev/null");
  79.  
  80.     print "Content-type: text/html\n\n";
  81.  
  82.     $ENV{'HOME'} = "/";
  83.     
  84.     open(WAISQ, "-|") || exec ($waisq, "-c", $waisd,
  85.                                 "-f", "-", "-S", "$src.src", "-g", @query);
  86.  
  87.     print "<HEAD>\n<TITLE>Search of ", $title, "</TITLE>\n</HEAD>\n";
  88.     print "<BODY>\n<H1>", $title, "</H1>\n";
  89.  
  90.     print "<HR><FORM method=\"GET\" action=\"/cgi-bin/newwais.pl/$src\">\n";
  91.     print "Enter keyword(s):\n";
  92.     print "<input name=\"isindex\" value=\"@query\" size=30></FORM><HR>\n";
  93.  
  94.     print "$title contains the following\n";
  95.     print "items relevant to <B>\`$pquery\':</B><P>\n";
  96.     print "<DL>\n";
  97.  
  98.     local($hits, $score, $headline, $lines, $bytes, $type, $date);
  99.  
  100.     print "<OL>";
  101.     while (<WAISQ>) {
  102.         /:score\s+(\d+)/ && ($score = $1);
  103.         /:number-of-lines\s+(\d+)/ && ($lines = $1);
  104.         /:number-of-bytes\s+(\d+)/ && ($bytes = $1);
  105.         /:type "(.*)"/ && ($type = $1);
  106.         /:headline "(.*)"/ && ($headline = $1);         # XXX
  107.         /:date "(\d+)"/ && ($date = $1, $hits++, &docdone);
  108.     }
  109.     print "</OL>";
  110.     close(WAISQ);
  111.     print "</DL>\n";
  112.  
  113.     if ($hits == 0) {
  114.         print "Nothing found.\n";
  115.     }
  116.     print "</BODY>\n";
  117. }
  118.  
  119.  
  120. sub docdone {
  121.  
  122.     if ($headline =~ /Search produced no result/) {
  123.         print "<HR>";
  124.     print "Search produced no result.";
  125. #        print $headline, "<P>\n<PRE>";
  126. # the following was &'safeopen
  127. #        open(WAISCAT, "$waisd/$src.cat") || die "$src.cat: $!";
  128. #        while (<WAISCAT>) {
  129. #            s#(Catalog for database:)\s+.*#$1 <STRONG>$src</STRONG>#;
  130. #            s#Headline:\s+(.*)#Headline: <A HREF="$1">$1</A>#;
  131. #            print;
  132. #        }
  133. #        close(WAISCAT);
  134. #        print "\n</PRE>\n";
  135.     } else {
  136.         $docname = $headline;
  137.     $docname =~ s/\.([^.]*)$//;
  138.     $extension= $1;
  139.     $docname =~ s/\/([^\/]*)$//;
  140.     $docname = $1;
  141.         print "<LI><A HREF=\"$headline\"><B>$docname</B></A>\n";
  142.     }
  143.     $score = $headline = $lines = $bytes = $type = $date = '';
  144. }
  145.  
  146. eval '&do_wais';
  147.